//JavaScript Document
function changelocal(local) {
	var currenthref = window.location.href;
	if (currenthref.indexOf("?") == -1) {
		go(currenthref + "?local=" + local);
	} else {
		if (currenthref.indexOf("local=") == -1) {
			go(currenthref + "&local=" + local);
		} else {
			var hrefprefix = currenthref.substring(0, currenthref
					.indexOf("local="));
			var hrefsuffixidx = currenthref.indexOf("&", currenthref
					.indexOf("local="));
			if (hrefsuffixidx == -1) {
				go(hrefprefix + "local=" + local);
			} else {
				var hrefsuffix = currenthref.substring(hrefsuffixidx,
						currenthref.length);
				go(hrefprefix + "local=" + local + hrefsuffix);
			}
		}
	}
}

function go(url) {
	window.location = url;
}

function goback() {
	window.history.go(-1);
}

function confirmgo(m, url) {
	if (confirm(m)) {
		window.location = url;
	}
}

function confirmsubmit(f, act, tip, v) {
	if (confirm(tip)) {
		dosubmit(f, act, v);
	}
}

function dosubmit(f, act, v) {
	if (!v || v.validate()) {
		if (act && $("action")) {
			$("action").value = act;
		}
		f.submit();
	}
}

var collapsible = function(target, t, s) {
	if (t == undefined) {
		t = "&nbsp;";
	}
	if (s == undefined) {
		s = "collapsed";
	}

	var trigger;
	var title;
	if (typeof t == "string") {
		trigger = new Element("a", {
			"class" : s,
			"href" : "javascript:;"
		}).insert(t);
		title = new Element("div", {
			"class" : "c-title-c"
		}).insert(trigger);		
	} else if (typeof t == "object") {
		trigger = $(t);
		trigger.addClassName(s);
		title = $(t).up();
		title.addClassName("c-title-x");
	}	
	var content;
	if ($(target)) {
		if (typeof t == "string") {
			var parent = $(target).up();

			content = Element.wrap($(target), new Element("div", {
				"class" : "c-content"
			}));

			var collapsible = new Element("div", {
				"class" : "collapsible"
			});
			collapsible.insert(title);
			collapsible.insert(content);
			parent.insert(collapsible);
		} else if (typeof t == "object") {
			content = $(target);
			content.addClassName("c-content");
		}
	}

	if (content != undefined) {
		if (s == "collapsed") {
			content.hide();
		} else if (s == "expanded") {
			content.show();
		}
	}

	if (trigger != undefined) {
		trigger.onclick = function() {
			if (trigger.hasClassName("collapsed")) {
				trigger.removeClassName("collapsed");
				trigger.addClassName("expanded");
				content.show();
			} else {
				trigger.addClassName("collapsed");
				trigger.removeClassName("expanded");
				content.hide();
			}
		}
	}
}

function selectOption(n, val) {	
	var obj = document.getElementById(n);
	for ( var i = 0; i < obj.options.length; i++) {
		if (obj.options[i].value == val) {
			obj.options[i].selected = true;
			return true;
		}
	}
	return false;
}